package com.gs.montaditos;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RandomOrder extends Activity {
	/** Called when the activity is first created. */
	EditText personsField;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.random);
        personsField = (EditText)findViewById(R.id.persons);
        Button plus = (Button)findViewById(R.id.plus);
        Button less = (Button)findViewById(R.id.less);
        Button okay = (Button)findViewById(R.id.okay);
        
        plus.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				int n = Integer.valueOf(personsField.getText().toString());
				personsField.setText(String.valueOf(n+1));
			}
        });
        
        less.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				int n = Integer.valueOf(personsField.getText().toString());
				if(n>1){
					personsField.setText(String.valueOf(n-1));
				}
			}
        });
        
        okay.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Order.reset();
				Montaditos.init(getApplicationContext());
				Random randomGenerator = new Random();
				int n = Integer.valueOf(personsField.getText().toString());
				for (int idx = 1; idx <= n; ++idx){
			      int randomInt = randomGenerator.nextInt(100);
			      Order.add(randomInt);
			    }
				startActivity(new Intent(getApplicationContext(), ListOrder.class));
				Toast.makeText(getApplicationContext(), "Order Done", Toast.LENGTH_LONG).show();
			}
		});
    }
}
